//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.Design.MatchingRules;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
using EntLibContrib.PolicyInjection.Configuration.Design.Properties;

namespace EntLibContrib.PolicyInjection.Configuration.Design.MatchingRules
{
	/// <summary>
	/// Or Matching Rule Node
	/// </summary>
	public class OrMatchingRuleNode : MatchingRuleNode, ICompositeMatchingRuleNode
	{
		private OrMatchingRuleData ruleData;

		/// <summary>
		/// Initializes a new instance of the <see cref="OrMatchingRuleNode"/> class.
		/// </summary>
		public OrMatchingRuleNode()
			: this(new OrMatchingRuleData(Resources.OrMatchingRuleName))
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="OrMatchingRuleNode"/> class.
		/// </summary>
		/// <param name="ruleData">The rule data.</param>
		public OrMatchingRuleNode(OrMatchingRuleData ruleData)
			: base(ruleData)
		{
			this.ruleData = ruleData;
		}


		/// <summary>
		/// Returns a <see cref="T:Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.MatchingRuleData"/> configuration object from the nodes data.
		/// </summary>
		/// <returns>
		/// A newly created <see cref="T:Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.MatchingRuleData"/> configuration object from the nodes data.
		/// </returns>
		/// <remarks>
		/// Subclasses implement this method to return an instance of a concrete <see cref="T:Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.MatchingRuleData"/> subclass.
		/// </remarks>
		public override MatchingRuleData GetConfigurationData()
		{
			OrMatchingRuleData matchingRuleData = new OrMatchingRuleData(this.Name);
			foreach (MatchingRuleNode node in this.Nodes)
			{
				matchingRuleData.MatchingRules.Add(node.GetConfigurationData());
			}
			return matchingRuleData;
		}

		#region ICompositeMatchingRuleNode Members

		/// <summary>
		/// Gets the child rules.
		/// </summary>
		/// <value>The child rules.</value>
		[Browsable(false)]
		public IEnumerable<MatchingRuleData> ChildRules
		{
			get { return ruleData.MatchingRules; }
		}

		#endregion
	}
}
